﻿<navigation:Page 
  x:Class="Demo.OData.Views.Basic" 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  mc:Ignorable="d"
  xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"

	xmlns:mac="clr-namespace:System.Windows.Controls;assembly=Slma.Windows.Controls"
	xmlns:mao="clr-namespace:System.Windows.Controls;assembly=Slma.Windows.Controls.OData"
	xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"						 
  xmlns:od="clr-namespace:System.Windows.Controls;assembly=Slma.OData"
  xmlns:service="clr-namespace:Demo.OData.CustomService"
  xmlns:local="clr-namespace:Demo.OData"
  xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"

  d:DesignWidth="800" d:DesignHeight="600"
  Title="Basic Page">
  <navigation:Page.Resources>
    <local:BoolNotConverter x:Key="BoolNotConverter" />
    <Style x:Key="styMar" TargetType="FrameworkElement">
      <Setter Property="Margin" Value="0,3,0,0"/>
    </Style>
  </navigation:Page.Resources>
  <Grid x:Name="LayoutRoot" DataContext="{Binding ElementName=dsProducts, Path=Data}">
    <od:ODataSource 
      x:Name="dsProducts" 
      EntitySetName="Products" 
      AddingNewEntity="dsProducts_AddedNew" >
      <od:ODataSource.DataServiceContext>
        <service:CustomContext />
      </od:ODataSource.DataServiceContext>
      <od:ODataSource.SortDescriptions>
        <od:SortDescriptionOData  PropertyName="Name" Direction="Ascending"  />
      </od:ODataSource.SortDescriptions>
    </od:ODataSource>

    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="580" />
        <ColumnDefinition Width="100"/>
        <ColumnDefinition Width="200"/>
        <ColumnDefinition />
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition Height="20" />
        <RowDefinition Height="Auto"/>
        <RowDefinition />
      </Grid.RowDefinitions>
      <StackPanel Grid.Row="0" Grid.ColumnSpan="4">
        <TextBlock x:Name="txbURL" Text="{Binding ElementName=dsProducts, Path=QueryURL}" TextWrapping="Wrap" VerticalAlignment="Stretch" />
      </StackPanel>
      <StackPanel Grid.Row="1" Grid.RowSpan="2" Grid.Column="0">
        <HyperlinkButton Content="The source code of control below is here http://datagridtoolbar.codeplex.com" NavigateUri="http://datagridtoolbar.codeplex.com/" TargetName="_blank" />
        <CheckBox  IsChecked="{Binding ElementName=tb1, Path=AutoSubmit, Mode=TwoWay}" Content="Auto submit mode" />
        <mao:DataGridToolBarOData  
        x:Name="tb1" Height="45" Margin="0,0,0,2" AutoSubmit="False" ButtonAddNewVisible="True" ButtonEditVisible="True"
				DataGrid="{ Binding ElementName=dgProducts, Mode=OneTime }"	
				ODataSource="{ Binding ElementName=dsProducts, Mode=OneTime}"
				CreateDataForm="DGRB_CreateDataForm"															 
				>
          <mao:DataGridToolBarOData.ColumnsForFiltering>
            <mac:DataGridToolBarFilterItem ColumnName="Name"  />
            <mac:DataGridToolBarFilterItem ColumnName="ProductNumber"  />
            <mac:DataGridToolBarFilterItem ColumnName="Color"  />
            <mac:DataGridToolBarFilterItem ColumnName="Size"  />
            <mac:DataGridToolBarFilterItem ColumnName="ListPrice"  />
            <mac:DataGridToolBarFilterItem ColumnName="Weight"  />
            <mac:DataGridToolBarFilterItem ColumnName="SellStartDate"  />
          </mao:DataGridToolBarOData.ColumnsForFiltering>
          <mao:DataGridToolBarOData.Content>
            <data:DataPager x:Name="dpTest" PageSize="10" Source="{Binding ElementName=dsProducts, Path=Data}" BorderThickness="0" Background="Transparent" ></data:DataPager>
          </mao:DataGridToolBarOData.Content>
        </mao:DataGridToolBarOData>

        <data:DataGrid x:Name="dgProducts" Height="300" AutoGenerateColumns="False" 	  
				IsReadOnly="False"							
				ItemsSource="{Binding ElementName=dsProducts, Path=Data }"
				>
          <data:DataGrid.Columns>
            <data:DataGridTextColumn Header="{StaticResource ls_product_name}"
						Width="130" MaxWidth="300" MinWidth="40" 
						Binding="{Binding Name}" />
            <data:DataGridTextColumn Header="{StaticResource ls_product_poductnumber}"
						Width="80" MaxWidth="300" MinWidth="40" 
						Binding="{Binding ProductNumber}"/>
            <data:DataGridTextColumn Header="{StaticResource ls_product_color}"
						Width="60" MaxWidth="300" MinWidth="30" 
						Binding="{Binding Color, Mode=TwoWay}"/>
            <data:DataGridTextColumn Header="{StaticResource ls_product_size}"
						Width="50" MaxWidth="300" MinWidth="30" 
						Binding="{Binding Size}"  ElementStyle="{StaticResource ElementStyle_right}"/>
            <data:DataGridTextColumn Header="{StaticResource ls_product_listprice}"
						Width="70" MaxWidth="300" MinWidth="30" 
						Binding="{Binding ListPrice }" ElementStyle="{StaticResource ElementStyle_right}" />
            <data:DataGridTextColumn Header="{StaticResource ls_product_weight}"
						Width="60" MaxWidth="300" MinWidth="30" 
						Binding="{Binding Weight}"  ElementStyle="{StaticResource ElementStyle_right}">
            </data:DataGridTextColumn>
            <data:DataGridTextColumn Header="{StaticResource ls_product_sellstartdate}"
						Width="80" MaxWidth="300" MinWidth="30" 
						Binding="{Binding SellStartDate, StringFormat=d}"  ElementStyle="{StaticResource ElementStyle_right}"/>
          </data:DataGrid.Columns>
        </data:DataGrid>
        <toolkit:DataForm  
          Margin="0,10,0,0" Header="Product detail" 
          AutoEdit="False" AutoCommit="False" 
          ItemsSource="{Binding Path=Data, ElementName=dsProducts}">

        </toolkit:DataForm>
      </StackPanel>
      
      <StackPanel Grid.Column="1" Grid.Row="1" Margin="10,10,0,0" Width="90">
        <StackPanel>
          <TextBlock Text="Methods"/>
          <TextBlock Text="Current Row" Style="{StaticResource styMar}"/>
          <Grid>
            <Button Content="Up" Width="40" HorizontalAlignment="Left" Click="RowUp_Click"/>
            <Button Content="Down" Width="40" Margin="45,0,0,0" HorizontalAlignment="Left"  Click="RowDown_Click"/>

          </Grid>
          <TextBlock Text="Page" Style="{StaticResource styMar}"/>
          <Grid>
            <Button Content="Up" Width="40" HorizontalAlignment="Left" Click="PageUp_Click" IsEnabled="{Binding Path=CanChangePage}" />
            <Button Content="Down" Width="40" Margin="45,0,0,0" HorizontalAlignment="Left"  Click="PageDown_Click"  IsEnabled="{Binding Path=CanChangePage}"/>
          </Grid>
          <Button Content="Refresh Data" Click="RefreshData_Click" Style="{StaticResource styMar}" IsEnabled="{Binding Path=CanLoad}"/>
          <Button Content="Remove Item" Click="RemoveItem_Click"  Style="{StaticResource styMar}"/>
          <Button Content="Update Item" Click="UpdateItem_Click"  Style="{StaticResource styMar}"/>
          <Button Content="Add Item A" Click="AddItemA_Click"  Style="{StaticResource styMar}"/>
          <Button Content="Add Item B" Click="AddItemB_Click"  Style="{StaticResource styMar}"/>
          <Button Content="Reject Changes" Click="RejectChanges_Click" IsEnabled="{Binding Path=HasChanges}" Style="{StaticResource styMar}" />
          <Button Content="Submit Changes" Click="SubmitChanges_Click" IsEnabled="{Binding Path=HasChanges}" Style="{StaticResource styMar}"/>
        </StackPanel>
      </StackPanel>

      <StackPanel Grid.Column="2" Grid.Row="1" Margin="10,10,0,0">
        <TextBlock Text="Properties"/>
        <CheckBox  Content="Get total count" IsChecked="{Binding Path=IsGetTotalCount, Mode=TwoWay}" Style="{StaticResource styMar}"/>
        <CheckBox  Content="IsBusy"   IsEnabled="False" IsChecked="{Binding Path=IsBusy}" Style="{StaticResource styMar}"/>
        <CheckBox  Content="IsLoading" IsEnabled="False" IsChecked="{Binding Path=IsLoading}" Style="{StaticResource styMar}"/>
        <CheckBox  Content="IsSubmitting" IsEnabled="False" IsChecked="{Binding Path=IsSubmitting}" Style="{StaticResource styMar}"/>
        <CheckBox  Content="CanLoad" IsEnabled="False" IsChecked="{Binding Path=CanLoad, Mode=TwoWay}" />
        <CheckBox  Content="CanChangePage" IsEnabled="False" IsChecked="{Binding Path=CanChangePage}" />
        <CheckBox  Content="Has changes" IsEnabled="False" IsChecked="{Binding Path=HasChanges}" />
        <Grid Style="{StaticResource styMar}">
          <TextBox  Width="30" HorizontalAlignment="Left" Text="{Binding Path=PageSize, Mode=TwoWay}" />
          <TextBlock Text="Page size" Margin="40,0,0,0" VerticalAlignment="Center" />
        </Grid>
        <Grid Style="{StaticResource styMar}">
          <TextBox  Width="30" HorizontalAlignment="Left" Text="{Binding Path=LoadSize, Mode=TwoWay}" />
          <TextBlock Text="Load size" Margin="40,0,0,0" VerticalAlignment="Center" />
        </Grid>
        <Grid Style="{StaticResource styMar}">
          <TextBox  Width="30" HorizontalAlignment="Left" Text="{Binding Path=CurrentPosition, Mode=TwoWay}" />
          <TextBlock Text="Current Item index" Margin="40,0,0,0" VerticalAlignment="Center" />
        </Grid>
        <Grid Style="{StaticResource styMar}">
          <TextBox  IsReadOnly="True" Width="30" HorizontalAlignment="Left" Text="{Binding Path=PageIndex}" />
          <TextBlock Text="Page index" Margin="40,0,0,0" VerticalAlignment="Center" />
        </Grid>
        <Grid Style="{StaticResource styMar}">
          <TextBox IsReadOnly="True" Width="30" HorizontalAlignment="Left" Text="{Binding Path=TotalItemCount}" />
          <TextBlock Text="Total item count" Margin="40,0,0,0" VerticalAlignment="Center" />
        </Grid>
      </StackPanel>
      
      <StackPanel Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2"  Margin="10,10,0,0">
        <Button Content="Sort Size des, Price" Click="Sort_Click" IsEnabled="{Binding Path=CanLoad}" Style="{StaticResource styMar}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" />
        <Button  Click="Filter01_Click" IsEnabled="{Binding Path=CanLoad}" Style="{StaticResource styMar}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" >
          <Button.Content>
            <TextBlock Text="Filter = Name contains 'mountain' AND (Color contains 'Silver' OR Color contains 'White')" TextWrapping="Wrap" />            
          </Button.Content>
        </Button>
        <Button Content="Clear Filter" Click="Button_Click" IsEnabled="{Binding Path=CanLoad}" Style="{StaticResource styMar}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" />
      </StackPanel>
      
    </Grid>
    <mac:WaitControl IsBusy="{Binding ElementName=dsProducts,Path=IsBusy,Mode=OneWay}" Cancel="WaitControl_Cancel" />
  </Grid>
</navigation:Page>
